/*
 * FiltrDialog.java
 *
 * Created on 15. prosinec 2006, 13:52
 */

package cz.results.winter6.view.dialogs.filtrdialog;

import cz.results.winter6.model.Filtr;
import cz.results.winter6.model.Filtry;
import javax.swing.JDialog;

/**
 *
 * @author  mike
 */
public class FiltrDialog extends JDialog {
    
    private Filtr filtr;
    private Filtry filtry;
    private boolean novyZaznam;
    
    public FiltrDialog(JDialog parent, boolean modal, Filtry filtry, Filtr filtr, boolean novyZaznam) {
        super(parent, modal);
        initComponents();
        setFiltr(filtr);
        setFiltry(filtry);
        this.novyZaznam = novyZaznam;
        jTextFieldNazev.setText(filtr.getNazev());
        jTextFieldPattern.setText(filtr.getVyraz());
        
    }
    
    public Filtr getFiltr() {
        return filtr;
    }
    
    public void setFiltr(Filtr filtr) {
        this.filtr = filtr;
    }
    
    public Filtry getFiltry() {
        return filtry;
    }
    
    public void setFiltry(Filtry filtry) {
        this.filtry = filtry;
    }
    
    
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabelNazev = new javax.swing.JLabel();
        jTextFieldNazev = new javax.swing.JTextField();
        jLabelPattern = new javax.swing.JLabel();
        jTextFieldPattern = new javax.swing.JTextField();
        jButtonOk = new javax.swing.JButton();
        jButtonZrus = new javax.swing.JButton();

        setTitle("Filtr");
        setAlwaysOnTop(true);
        setLocationByPlatform(true);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jLabelNazev.setText("n\u00e1zev filtru:");
        jLabelNazev.setFocusable(false);

        jTextFieldNazev.setNextFocusableComponent(jTextFieldPattern);

        jLabelPattern.setText("pattern:");

        jTextFieldPattern.setNextFocusableComponent(jButtonOk);

        jButtonOk.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/results/winter6/view/icons/button_ok.png")));
        jButtonOk.setText("ok");
        jButtonOk.setNextFocusableComponent(jButtonZrus);
        jButtonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOkActionPerformed(evt);
            }
        });

        jButtonZrus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cz/results/winter6/view/icons/button_cancel.png")));
        jButtonZrus.setText("zru\u0161");
        jButtonZrus.setNextFocusableComponent(jTextFieldNazev);
        jButtonZrus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonZrusActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextFieldPattern, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
                    .add(jLabelPattern)
                    .add(jTextFieldNazev, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 311, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabelNazev, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 92, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(193, 193, 193)
                .add(jButtonOk, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                .add(40, 40, 40)
                .add(jButtonZrus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 98, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(190, 190, 190))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jLabelNazev)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextFieldNazev, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(16, 16, 16)
                .add(jLabelPattern)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextFieldPattern, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(27, 27, 27)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonZrus)
                    .add(jButtonOk))
                .addContainerGap(13, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButtonZrusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonZrusActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jButtonZrusActionPerformed
    
    private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
        if(!(jTextFieldNazev.getText().trim().equals("") && jTextFieldPattern.getText().trim().equals("")) ){
            filtr.setNazev(jTextFieldNazev.getText().trim());
            filtr.setVyraz(jTextFieldPattern.getText().trim());
            
            if(novyZaznam){
                filtry.add(filtr);
            }
        }
        
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jButtonOkActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    
    
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonOk;
    private javax.swing.JButton jButtonZrus;
    private javax.swing.JLabel jLabelNazev;
    private javax.swing.JLabel jLabelPattern;
    private javax.swing.JTextField jTextFieldNazev;
    private javax.swing.JTextField jTextFieldPattern;
    // End of variables declaration//GEN-END:variables
    
}
